.store-dropdown {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 0.5rem;
  padding-right: 0.75rem;
  background-color: $sidebar-bg;
  width: $sidebar-width;
  border-right: 1px solid $border-color;
  height: calc($header-height + 1px);
  transition: width 0.1s ease;
}

.store-dropdown-button {
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  gap: 0.5rem;
  box-shadow: none !important;

  &:hover {
    background-color: $gray-50;
  }
}

.store-chooser {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.25rem;
  margin: 0.25rem;
  border: 1px solid $border-color;
  border-radius: $border-radius-lg;

  .store-chooser-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: $border-radius;
    padding: 0.25rem;
    text-wrap: nowrap;

    &:hover {
      text-decoration: none;
      background-color: $dropdown-link-hover-bg;
    }

    &.active {
      cursor: not-allowed;
      background-color: $action;
    }
  }
}

// User dropdown in sidebar
.user-dropdown {
  position: fixed;
  bottom: 0;
  left: 0;
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.5rem;
  background-color: $sidebar-bg;
  width: $sidebar-width;
  border-right: 1px solid $border-color;
  border-top: 1px solid $border-color;
  transition: width 0.1s ease;
  z-index: 10;

  @media (min-width: 992px) {
    display: flex;
  }

  > .dropdown {
    width: 100%;
    overflow: hidden;
  }
}

.user-dropdown-button {
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  gap: 0.5rem;
  box-shadow: none !important;
  width: 100%;
  overflow: hidden;

  &:hover {
    background-color: $gray-50;
  }

  .user-name {
    flex: 1;
    width: 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
  }
}

// Toggle button
.sidebar-toggle-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: $border-radius;
  background-color: transparent;
  border: none;
  z-index: 10;

  &:hover {
    background-color: $gray-50;
  }
}

#main-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: $sidebar-width;
  background-color: $sidebar-bg;
  box-shadow: inset -1px 0 0 $border-color;
  height: calc(100vh - $header-height);
  overflow-x: hidden;
  position: fixed;
  top: $header-height;
  padding-top: 0.8rem;
  transition: width 0.1s ease, padding 0.1s ease;

  @media (max-width: 992px) {
    display: none;
  }

  // Sidebar content
  .sidebar-content {
    opacity: 1;
    transition: opacity 0.2s ease;
  }

  .nav {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    gap: 0.25rem;
    display: flex;
    flex-direction: column;
  }

  .nav-link {
    border-radius: $border-radius-lg;
    display: flex;
    align-items: center;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    color: inherit;
    white-space: nowrap;
    transition: background-color 0.1s ease-in-out;

    .ti {
      margin-right: 0.5rem;
      border-radius: $border-radius;
      padding: 0.2rem 0.2rem;
      flex-shrink: 0;
    }

    &:hover {
      background-color: $gray-50;

      .ti {
        color: theme-color('primary');
      }
    }
    &.active {
      color: theme-color('primary');
      background-color: $white;
      box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0.04) 0px 0px 0px 1px, rgba(0, 0, 0, 0.04) 0px 1px 2px -1px, rgba(0, 0, 0, 0.02) 0px 2px 4px 0px;
      font-weight: $font-weight-medium;

      .ti {
        background-color: theme-color('primary');
        color: $white;
      }
    }

    .badge:not(.badge-info) {
      @extend .badge-light;
      border-radius: $border-radius;
    }
  }

  .nav-submenu {
    display: flex;
    flex-direction: column;
    list-style: none;
    padding-top: 0.25rem;
    padding-left: 2rem;
    &:before {
      content: '';
      position: absolute;
      left: 1rem;
      top: 0;
      bottom: 0.25rem;
      width: 1px;
      background-color: $gray-200;
    }
    position: relative;

    .nav-link {
      font-weight: 400;
      padding-top: 0.25rem;
      padding-bottom: 0.25rem;

      &:hover {
        background-color: $gray-50;
      }
      &.active, &:active, &:focus {
        font-weight: 600;
        background-color: transparent !important;
        box-shadow: none;

        &:before {
          content: '';
          position: absolute;
          left: calc(-1rem - 1px);
          top: 10%;
          width: 3px;
          height: 80%;
          background-color: theme-color('primary');
          border-radius: $border-radius-sm;
        }
      }
    }
  }

  .dropdown {
    padding-left: 0.5rem;
    padding-right: 0.5rem;

    .btn {
      padding: 0.25rem 0.25rem;
      border-radius: $border-radius;
      display: flex;
      align-items: center;

      &:hover, &:focus, &:active {
        background-color: $gray-50;
      }
    }

    .dropdown-menu {
      width: calc(100% - 1rem) !important;
    }
  }
}

// Disable transitions during initial page load to prevent animation flash
body.sidebar-no-transition {
  #main-sidebar,
  .store-dropdown,
  .user-dropdown,
  #content,
  .sidebar-toggle-btn {
    transition: none !important;
  }
}

// Collapsed state
body.sidebar-collapsed {
  .sidebar-toggle-btn {
    transform: rotate(180deg);
  }

  #main-sidebar {
    width: $sidebar-width-collapsed;
    padding-left: 0;
    padding-right: 0;

    .sidebar-content {
      // Keep content visible but modify layout
      opacity: 1;
      pointer-events: auto;

      .nav > .nav-item > .nav-link {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
        width: 40px;
        height: 40px;
        margin: 0 auto;
        overflow: visible;
        font-size: 0;
        position: relative;
  
        .ti {
          margin-right: 0;
          font-size: 1.25rem;
        }
  
        // Hide text labels (direct text nodes)
        span:not(.badge) {
          display: none;
        }
  
        // Position badges as notification counters
        .badge {
          display: flex;
          position: absolute;
          top: 0;
          right: 0;
          transform: translate(25%, -25%);
          min-width: 18px;
          height: 18px;
          padding: 0 0.25rem;
          font-size: 0.625rem;
          line-height: 18px;
          border-radius: 9px;
          justify-content: center;
          align-items: center;
        }
      }

      #nav-link-vendors .badge {
        display: none !important;
      }

      .nav-section-header {
        width: $sidebar-width-collapsed - 20px;
        span {
          display: none;
        }
      }
    }

    .nav {
      padding-left: 0;
      padding-right: 0;
      align-items: center;
    }

    // Hide submenus and dropdowns when collapsed
    .nav-submenu,
    .dropdown {
      display: none;
    }

    // Hide enterprise edition notice
    #enterprise-edition-notice {
      display: none;
    }

    // Hide any mt-auto sections
    .mt-auto {
      display: none;
    }

    .nav-submenu {
      gap: 0.25rem !important;
    }
  }

  .store-dropdown {
    width: $sidebar-width-collapsed;
    overflow: visible;
    justify-content: center;
    padding-left: 0;
    padding-right: 0;

    #new-item-dropdown,
    .store-name {
      display: none !important;
    }

    .store-dropdown-button {
      width: 44px;
      height: 44px;
      padding: 0.25rem;
      justify-content: center;
      overflow: hidden;

      // Hide dropdown toggle arrow
      &::after {
        display: none;
      }

      .store-logo, img, .ti {
        margin: 0;
      }

      // Keep the icon/logo element visible
      .rounded-sm, .bg-white, .border, .text-dark, .bg-gray-200,
      div[class*="rounded"], div[class*="bg-"] {
        display: flex !important;
        width: 32px;
        height: 32px;
        font-size: 1rem;
      }

      // Hide all text spans and chevron when collapsed
      span:not([class*="rounded"]):not([class*="bg-"]),
      .ti-chevron-down,
      small,
      strong {
        display: none;
      }

      // Keep only icons/logos visible
      img, .ti:not(.ti-chevron-down) {
        display: block;
      }
    }
  }

  .user-dropdown {
    width: $sidebar-width-collapsed;
    overflow: visible;
    justify-content: center;
    padding-left: 0;
    padding-right: 0;

    .dropdown {
      display: block !important;
    }

    .user-name {
      display: none !important;
    }

    .user-dropdown-button {
      width: 44px;
      height: 44px;
      padding: 0.25rem;
      justify-content: center;
      overflow: visible;

      // Hide dropdown toggle arrow
      &::after {
        display: none;
      }

      // Keep avatar visible and centered
      .avatar {
        display: flex !important;
        margin: 0;
      }
    }
  }

  #content {
    @media (min-width: 992px) {
      margin-left: $sidebar-width-collapsed + 1px;
    }
  }
}

// Mobile Sidebar
.sidebar-mobile {
  position: fixed;
  inset: 0;
  z-index: 1050;
  visibility: hidden;
  pointer-events: none;

  .sidebar-backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba($black, 0.5);
    opacity: 0;
    transition: opacity 0.1s ease;
  }

  .sidebar-panel {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: $sidebar-width;
    background-color: $sidebar-bg;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.1s ease;
    box-shadow: $box-shadow-lg;
    display: flex;
    flex-direction: column;

    .sidebar-mobile-header {
      display: flex;
      justify-content: flex-end;
      padding: 0.75rem;
      border-bottom: 1px solid $border-color;
      background-color: $sidebar-bg;
      position: sticky;
      top: 0;
      z-index: 1;

      .btn {
        padding: 0.25rem;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }

    .sidebar-mobile-content {
      padding-top: 0.5rem;
      flex: 1;
      overflow-y: auto;

      // Match desktop expanded sidebar styles
      .nav {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        gap: 0.25rem;
        display: flex;
        flex-direction: column;
      }

      .nav-link {
        border-radius: $border-radius-lg;
        display: flex;
        align-items: center;
        padding-left: 0.25rem;
        padding-right: 0.25rem;
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
        color: inherit;
        white-space: nowrap;
        transition: background-color 0.1s ease-in-out;

        .ti {
          margin-right: 0.5rem;
          border-radius: $border-radius;
          padding: 0.2rem 0.2rem;
          flex-shrink: 0;
        }

        &:hover {
          background-color: $gray-50;

          .ti {
            color: theme-color('primary');
          }
        }

        &.active {
          color: theme-color('primary');
          background-color: $white;
          box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0.04) 0px 0px 0px 1px, rgba(0, 0, 0, 0.04) 0px 1px 2px -1px, rgba(0, 0, 0, 0.02) 0px 2px 4px 0px;
          font-weight: $font-weight-medium;

          .ti {
            background-color: theme-color('primary');
            color: $white;
          }
        }

        .badge:not(.badge-info) {
          @extend .badge-light;
          border-radius: $border-radius;
        }
      }

      .nav-submenu {
        display: flex;
        flex-direction: column;
        list-style: none;
        padding-top: 0.25rem;
        padding-left: 2rem;
        position: relative;

        &:before {
          content: '';
          position: absolute;
          left: 1rem;
          top: 0;
          bottom: 0.25rem;
          width: 1px;
          background-color: $gray-200;
        }

        .nav-link {
          font-weight: 400;
          padding-top: 0.25rem;
          padding-bottom: 0.25rem;

          &:hover {
            background-color: $gray-50;
          }

          &.active, &:active, &:focus {
            font-weight: 600;
            background-color: transparent !important;
            box-shadow: none;

            &:before {
              content: '';
              position: absolute;
              left: calc(-1rem - 1px);
              top: 10%;
              width: 3px;
              height: 80%;
              background-color: theme-color('primary');
              border-radius: $border-radius-sm;
            }
          }
        }
      }

      .dropdown {
        padding-left: 0.5rem;
        padding-right: 0.5rem;

        .btn {
          padding: 0.25rem 0.25rem;
          border-radius: $border-radius;
          display: flex;
          align-items: center;

          &:hover, &:focus, &:active {
            background-color: $gray-50;
          }
        }

        .dropdown-menu {
          width: calc(100% - 1rem) !important;
        }
      }
    }

    // User dropdown in mobile sidebar
    .user-dropdown {
      position: relative;
      display: flex;
      width: 100%;
      border-right: none;
      border-top: 1px solid $border-color;
      margin-top: auto;
    }
  }

  &.sidebar-mobile-open {
    visibility: visible;
    pointer-events: auto;

    .sidebar-backdrop {
      opacity: 1;
    }

    .sidebar-panel {
      transform: translateX(0);
    }
  }
}

#enterprise-edition-notice {
  @extend .alert;
  @extend .alert-info;

  background-image: none;
  position: relative;
  font-size: $font-size-sm;
  padding: 0.5rem 1rem;
  margin: 0.75rem;
  border-width: 1px;
  box-shadow: $box-shadow-xs;
  p {
    margin-bottom: 0.5rem;
  }

  .btn-close {
    position: absolute;
    right: 0.25rem;
    top: 0.25rem;
    color: inherit !important;

    &:hover {
      background-color: transparent !important;
    }
  }
}